﻿<template>
  <div class="addPrestudyRecord">
    <el-form :model="form" label-width="98px" ref="form" :rules="rules" :hide-required-asterisk="true"
      label-position="left">
      <el-row :gutter="30">
        <el-col :span="24">
          <el-form-item label="名称" prop="classTitle">
            <el-input v-model.trim="form.classTitle" placeholder="请输名称" clearable maxlength="15" />
          </el-form-item>
        </el-col>
        <el-col align="right">
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" class="btnbgc" @click="save('form')" :loading="loading">提交</el-button>
        </el-col>
      </el-row>
    </el-form>

  </div>
</template>
<script>
  export default {
    name: "addPrestudyRecord",
    data() {
      return {
        loading: false,
        form: {

        },
        rules: {
          classTitle: [{
            required: true,
            message: "请输名称",
            trigger: "blur"
          }],

        },
      };
    },
    methods: {
      save(formName) {
        this.loading = true;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.singleData) {
              this.form.dutyDate = this.dateShow
              this.$emit("propClose", '取消');
            } else {
              this.form.dutyDate = this.dateShow
              this.$emit("propClose", this.form);
            }
          } else {
            //console.log("error submit!!");
            this.loading = false;
            return false;
          }
        });
      },
      cancel() {
        this.$emit("propClose", '取消');
      },
      singleShow() {
        if (this.singleData) {
          this.form = this.singleData;
        }
      },
    },
    props: {
      singleData: {
        type: [Object || null]
      },
      dateShow: {
        type: String
      }

    },
    created() {
      this.singleShow();
    },



  };
</script>
<style lang="scss" scoped>
  .addPrestudyRecord::v-deep {
    .el-form-item {
      >label::after {
        content: "*";
        color: #f56c6c;
        margin-left: 4px;
      }
    }

    .addPrestudyRecord-nmust {
      .el-form-item {
        >label::after {
          content: "";
        }
      }
    }

    .el-form-item__label {
      color: #5a6066;
      font-size: 14px;
      font-weight: normal;
    }
  }

  .addPrestudyRecord {
    &-input {
      width: 100%;
    }
  }
</style>
